using System;
using System.CodeDom.Compiler;
using System.Runtime.Serialization;
using System.Text;

namespace PrismFactory.SoftwareFactory.Actions.Temp
{
    [Serializable]
    public class TemplateException : Exception
    {
        // Fields
        private CompilerErrorCollection compilerErrors;
        private string renderedErrors;

        // Methods
        public TemplateException(CompilerErrorCollection compilerErrors)
        {
            this.compilerErrors = compilerErrors;
        }

        protected TemplateException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        public override string ToString()
        {
            if (this.renderedErrors == null)
            {
                StringBuilder builder = new StringBuilder();
                foreach (CompilerError error in this.compilerErrors)
                {
                    builder.Append(error.ErrorText);
                    builder.Append(Environment.NewLine);
                    builder.Append(new string('-', 100));
                    builder.Append(Environment.NewLine);
                }
                this.renderedErrors = builder.ToString();
            }
            return this.renderedErrors;
        }

        // Properties
        public CompilerErrorCollection CompilerErrors
        {
            get
            {
                return this.compilerErrors;
            }
            set
            {
                this.compilerErrors = value;
            }
        }
    }

 

}